package com.ocean.common.exception;

import com.ocean.common.commons.JhCommonError;

/**
 * @Author: FuGui Wang
 * @Description: TODO 系统通用包装器业务异常类实现
 * @Date 2022/12/5
 * @Version V1.1.0
 */
public class OceanException extends RuntimeException implements JhCommonError {

    /**
     * 声明一个通用异常处理接口
     */
    private final JhCommonError commonError;

    /**
     * 直接接收EmBusinessError的传参，用于构造业务异常
     *
     * @param commonError 通用异常处理接口
     */
    public OceanException(JhCommonError commonError) {
        super();
        this.commonError = commonError;
    }

    /**
     * 接收自定义errMsg的方式后再业务异常
     *
     * @param commonError 通用异常处理接口
     * @param errMsg      返回错误提示信息
     */
    public OceanException(JhCommonError commonError, String errMsg) {
        super();
        this.commonError = commonError;
        this.commonError.setErrMsg(errMsg);
    }

    @Override
    public int getErrCode() {
        return this.commonError.getErrCode();
    }

    @Override
    public String getErrMsg() {
        return this.commonError.getErrMsg();
    }

    @Override
    public JhCommonError setErrMsg(String errMsg) {
        this.commonError.setErrMsg(errMsg);
        return this;
    }
}
